﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Common.Enums;
using ZhimeiSoft.Framework.Common.MathUtils;
using ZhimeiSoft.CharmManager.DOL;


namespace ZhimeiSoft.CharmManager.Client.Forms.Control.ServiceItem
{
    public partial class frmServiceItemPlanAdd : FormBase
    {
        private ControlClassModeEnum _mode;
        private DBEntityServiceItemDetail _detail;

        public ControlClassModeEnum Mode
        {
            get { return _mode; }
            set { _mode = value; }
        }

        public DBEntityServiceItemDetail ServiceItemDetailInfo
        {
            get { return _detail; }
            set { _detail = value; }
        }

        public frmServiceItemPlanAdd()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private bool Validation()
        {
            string sSeqNum = txtSeqNum.Text.Trim();
            string sDays = txtDays.Text.Trim();
            string error = "";
            if (sSeqNum == string.Empty)
            {
                error = "请输入序号。";
                MsgBox.MsgInfo(error);
                txtSeqNum.Focus();
                SetErrorControl(txtSeqNum, error);
                return false;
            }
            if (!NumberUtil.IsNumber(sSeqNum))
            {
                error = "序号应为正整数。";
                MsgBox.MsgInfo(error);
                txtSeqNum.Focus();
                SetErrorControl(txtSeqNum, error);
                return false;
            }
            if (sDays == string.Empty)
            {
                error = "请输入间隔天数。";
                MsgBox.MsgInfo(error);
                txtDays.Focus();
                SetErrorControl(txtDays, error);
                return false;
            }
            if (!NumberUtil.IsNumber(sDays))
            {
                error = "间隔天数应为正整数。";
                MsgBox.MsgInfo(error);
                txtDays.Focus();
                SetErrorControl(txtDays, error);
                return false;
            }
            return true;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Validation() == false)
                return;

            if (_mode == ControlClassModeEnum.emInsert)
            {
                _detail = new DBEntityServiceItemDetail();
            }
            _detail.SEQNUM = Convert.ToInt32(txtSeqNum.Text.Trim());
            _detail.SDAYS = Convert.ToInt32(txtDays.Text.Trim());
            _detail.SMEMO = txtMemo.Text;
            this.DialogResult = DialogResult.OK;
        }

        private void frmServiceItemPlanAdd_Shown(object sender, EventArgs e)
        {
            if (_mode == ControlClassModeEnum.emEdit)
            {
                txtSeqNum.Text = _detail.SEQNUM.ToString();
                txtDays.Text = _detail.SDAYS.ToString();
                txtMemo.Text = _detail.SMEMO;
            }
        }
    }
}
